package org.wendu.wdoa.exam.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wendu.wdoa.common.CurrentUser;
import org.wendu.wdoa.common.Result;
import org.wendu.wdoa.common.WdoaConstants;
import org.wendu.wdoa.common.token.TokenUtils;
import org.wendu.wdoa.exam.dto.leavequeryDto;
import org.wendu.wdoa.exam.model.leave;
import org.wendu.wdoa.exam.service.ExamService;

import java.util.Map;

@RestController
@RequestMapping("/exam")
public class ExamApi {
    @Autowired
    private  ExamService examService;
    @GetMapping("/MgrLeaveList")
    public Result MgrLeaveList(@RequestHeader(WdoaConstants.HEADER_NAME_TOKEN) String clientToken, leavequeryDto leaveQuery){
        CurrentUser currentUser = TokenUtils.getCurrentUser(clientToken);
        Map<String,Object> page = examService.getMgrLeaveList(currentUser.getUserId(),leaveQuery);
        return Result.OK(page);
    }
    @PostMapping("/checkLeaveList")
    public Result checkLeaveList(@RequestHeader(WdoaConstants.HEADER_NAME_TOKEN) String clientToken,@RequestBody leave leave){
        CurrentUser currentUser = TokenUtils.getCurrentUser(clientToken);
        examService.checkLeave(currentUser.getUserName(),leave);
        return Result.OK();
    }

}
